package Test10;

import java.io.*;
import java.util.Scanner;

public class Test101 {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        System.out.println("请输入要复制的文件路径：");
        String s=in.next();
        File file=new File(s);
        if(!file.isFile()){
            System.out.println(" 输入有误");
            return ;
        }

        System.out.println("请输入要复制到的文件路径：");
        String st=in.next();
        File file1=new File(st);
        if(!file1.isFile()){
            System.out.println(" 输入有误");
            return ;
        }
        System.out.println("是否要进行复制：Y/N");
        String str=in.next();
        if(str.toLowerCase().equals("y")){
            try(InputStream inputStream=new FileInputStream(file.getAbsoluteFile())){
                try(OutputStream outputStream=new FileOutputStream(file1.getAbsoluteFile())){
                    while(true) {
                        byte[] b = new byte[3];
                        int a = inputStream.read(b);
                        if (a == -1) {
                            System.out.println(" 复制完成 ");
                            break;
                        }
                        for(int i=0;i<a;i++){
                            outputStream.write(b[i]);
                        }

                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else{
            System.out.println("取消复制");
        }
    }
}
